#pragma once
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
#include "Player.h"
#include "AIPlayer.h"
#include "LocalPlayer.h"
#include "RemotePlayer.h"
#include "Piece.h"
#include <vector>

class Game
{
public:
	static void tournamentStart(char *, int);enum Turn
	{
		Player2Piece,
		Player1Move, 
		Player1Piece,
		Player2Move,
		Error //Debugging and exception handling purposes
	};
	static void start(void);
	static bool thereIsPiece(Location location);
	static bool thereIsPiece(Location location, std::vector<Piece> my_pieces);
	static bool thereArePiecesLeft(void);
	static bool thereArePiecesLeft(std::vector<Piece> my_pieces);
	static bool isInFinalState(void);
	static bool isInFinalState(std::vector<Piece> my_pieces);
	static bool hasCommonTraits(Location l1, Location l2, Location l3, Location l4);
	static bool hasCommonTraits(Location l1, Location l2, Location l3, Location l4, std::vector<Piece> my_pieces);
	static Turn whoStarted(void) {return m_whoStarted; }

	
private:
	static char * translatePieceToServer(Piece *);
	static bool isExiting(void){return m_gameState == Game::Exiting;}
	static void gameLoop(void);
	static void showSplashScreen(void);
	static void showMenu(void);
	static void showNewGameMenu(void);
	static void showGameOverMenu(unsigned char);

	struct PieceVisuals
	{
		sf::Texture texture;
		sf::Sprite sprite;

		void load(std::string filePath)
		{
			if(texture.loadFromFile(filePath))
			{
				sprite.setTexture(texture);
			}else
			{
				//exception handling
			}
		}

		void setPosition(float x, float y)
		{
			sprite.setPosition(x,y);
		}

		void draw(sf::RenderWindow & window)
		{
			window.draw(sprite);
		}
	};
	
	static void updateVisuals(std::vector<PieceVisuals> &, std::vector<Piece>&);

	enum State
	{
		Uninitialized,
		ShowingSplash,
		Paused,
		ShowingMenu,
		NewGameMenu,
		Playing,
		GameOver,
		Exiting
	};

	/*enum Turn
	};*/
	enum Type
	{
		LocalVsLocal,
		LocalVsAI,
		AIVsAI,
		LocalVsRemote,
		AIVsRemote,
		TypeError //Debugging and exception handling purposes
	};

	static State m_gameState;
	static Turn m_gameTurn;
	static Type m_gameType;
    static sf::RenderWindow m_mainWindow;
	static Player * m_pPlayer1;
	static Player * m_pPlayer2;
	static std::vector<Piece> m_pieces;
	static unsigned char m_winner;
	static Piece * m_currentPiece;
	static bool m_piecesLeft;
	static sf::Texture m_boardTexture;
	static sf::Sprite m_boardSprites[4][4];
	static std::vector<PieceVisuals> m_piecesVisuals;
	static Turn m_whoStarted;

};

